package com.huatai.bi.controller;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.huatai.bi.service.BigScreenDataSetService;
import com.huatai.bi.service.OpenApiService;
import com.huatai.bi.vo.bigScreenVO.ApiPageDataVO;
import com.huatai.bi.vo.bigScreenVO.DataSetTreeVO;
import com.huatai.bi.vo.excelVo.HeardVO;
import com.huatai.common.api.R;
import com.huatai.common.error.exception.ServiceException;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @BelongsProject: itc-airport-cloud
 * @BelongsPackage: com.huatai.bi.controller
 * @Author: hecaiy
 * @CreateTime: 2024-07-23  14:04
 * @Description: TODO
 * @Version: 1.0
 */
@RestController
@RequestMapping("/openApi")
@ApiOperation("开放接口")
public class ApiController {

    @Autowired
    private OpenApiService openApiService;
    @Autowired
    BigScreenDataSetService bigScreenDataSetService;

    @PostMapping("/query")
    @ApiOperation("查询接口")
    public R<ApiPageDataVO> query(@RequestBody Map<String,Object> params){
        Object object = params.get("apiIdentifier");
        if(ObjectUtil.isEmpty(object)){
            throw new ServiceException("接口唯一标识apiIdentifier未传，请传入");
        }
        return R.data(openApiService.query(object.toString(), params));
    }

    @PostMapping("/getDataSetColumnsList")
    @ApiOperation("获取数据集数据项")
    public R<List<HeardVO>> getDataSetColumnsList(@RequestBody JSONObject params){
        Long object = params.getLong("apiIdentifier");
        if(ObjectUtil.isEmpty(object)){
            throw new ServiceException("接口唯一标识apiIdentifier未传，请传入");
        }
        return R.data(openApiService.getDataSetColumnsList(object));
    }

    @PostMapping("/monitorDataSet")
    @ApiOperation("监控数据集")
    public R<DataSetTreeVO> getDataSetColumnsList(){
        return R.data(bigScreenDataSetService.monitorTree());
    }
}
